import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { markRaw } from 'vue';

import { DictEnum } from '@vben/constants';

import { Image } from 'ant-design-vue';
// import { VbenIcon } from '@vben/icons';
// import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
import { z } from '#/adapter/form';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

import MeetingChargeMode from './meeting-charge-mode.vue';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '会议名称',
  },
  {
    component: 'Input',
    fieldName: 'theme',
    label: '会议主题',
  },
  {
    component: 'MeetingSeriesSelect',
    fieldName: 'seriesId',
    label: '会议系列',
  },
  {
    component: 'Select',
    componentProps: {
      options: getDictOptions(DictEnum.EXHIBITION_YEAR),
    },
    fieldName: 'year',
    label: '年份',
  },
  {
    component: 'RangePicker',
    fieldName: 'time',
    label: '会议时间',
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    field: 'name',
    title: '会议名称',
    minWidth: 450,
  },
  {
    field: 'theme',
    title: '会议主题',
    width: 200,
    visible: false,
  },
  {
    field: 'meetingTime',
    title: '会议时间',
    width: 350,
    slots: { default: 'meetingTime' },
    showOverflow: false,
  },
  {
    field: 'enrollCount',
    title: '报名人数',
    width: 130,
  },
  {
    field: 'chargeType',
    title: '收费类型',
    width: 130,
    slots: {
      default: ({ row }) => {
        return renderDict(row.chargeType, DictEnum.MEETING_CHARGE_TYPE, true);
      },
    },
    visible: false,
  },
  {
    field: 'isTop',
    title: '置顶展示',
    width: 130,
    slots: {
      default: ({ row }) => {
        return renderDict(row.isTop, DictEnum.BUSINESS_YES_NO, true);
      },
    },
    visible: false,
  },
  {
    field: 'isRealName',
    title: '实名填写',
    width: 130,
    slots: {
      default: ({ row }) => {
        return renderDict(row.isRealName, DictEnum.BUSINESS_YES_NO, true);
      },
    },
    visible: false,
  },
  {
    field: 'hasEntryCode',
    title: '显示入场码',
    width: 140,
    slots: {
      default: ({ row }) => {
        return renderDict(row.hasEntryCode, DictEnum.BUSINESS_YES_NO, true);
      },
    },
    visible: false,
  },
  {
    field: 'isAudit',
    title: '需要审核',
    width: 130,
    slots: {
      default: ({ row }) => {
        return renderDict(row.isAudit, DictEnum.BUSINESS_YES_NO, true);
      },
    },
    visible: false,
  },
  {
    field: 'isWebSiteDisplay',
    title: '官网展示',
    width: 130,
    slots: {
      default: ({ row }) => {
        return renderDict(row.isWebSiteDisplay, DictEnum.BUSINESS_YES_NO, true);
      },
    },
    visible: false,
  },
  {
    field: 'isMiniProgramDisplay',
    title: '小程序展示',
    width: 140,
    slots: {
      default: ({ row }) => {
        return renderDict(
          row.isMiniProgramDisplay,
          DictEnum.BUSINESS_YES_NO,
          true,
        );
      },
    },
    visible: false,
  },
  {
    field: 'isRegisterPageDisplay',
    title: '登记页推荐',
    width: 140,
    slots: {
      default: ({ row }) => {
        return renderDict(
          row.isRegisterPageDisplay,
          DictEnum.BUSINESS_YES_NO,
          true,
        );
      },
    },
    visible: false,
  },
  {
    field: 'isDirect',
    title: '定向展示',
    width: 140,
    slots: {
      default: ({ row }) => {
        return renderDict(row.isDirect, DictEnum.BUSINESS_YES_NO, true);
      },
    },
    visible: false,
  },
  {
    field: 'remark',
    title: '备注',
    width: 300,
    visible: false,
  },
  {
    title: '创建人',
    field: 'createByName',
    width: 140,
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 180,
    visible: false,
  },
  {
    title: '最后更新人',
    field: 'updateByName',
    width: 140,
    visible: false,
  },
  {
    title: '最后更新时间',
    field: 'updateTime',
    width: 180,
    visible: false,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: 'ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '会议类型',
    fieldName: 'type',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Divider',
    componentProps: {
      id: 'basicInfo',
      orientation: 'center',
    },
    fieldName: 'basicInfo',
    formItemClass: 'col-span-2',
    hideLabel: true,
    renderComponentContent: () => ({
      default: () => '会议基本信息',
    }),
  },
  {
    component: 'Input',
    fieldName: 'name',
    label: '会议名称',
    rules: 'required',
  },
  {
    component: 'MeetingSeriesSelect',
    fieldName: 'seriesId',
    label: '会议系列',
  },
  {
    component: 'Input',
    fieldName: 'theme',
    label: '会议主题',
  },
  {
    component: 'Input',
    fieldName: 'sponsor',
    label: '主办方',
  },
  {
    component: 'Input',
    fieldName: 'address',
    label: '会议地点',
  },
  {
    component: 'RangePicker',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'time',
    label: '会议时间',
  },
  {
    component: 'CompanyTagSelect',
    fieldName: 'labelIds',
    label: '会议标签',
    defaultValue: [],
    help: '可多选，关联企业标签',
    rules: 'selectRequired',
  },
  {
    component: 'Input',
    fieldName: 'liveStreamUrl',
    label: '直播地址',
    help: '官网会议详情页将显示直播视频板块',
  },
  {
    component: 'FileUpload',
    fieldName: 'thumbnailOssId',
    label: '缩略图',
    componentProps: {
      accept: '.jpg,.jpeg,.png',
    },
    rules: 'selectRequired',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 0,
    fieldName: 'isTop',
    label: '置顶展示',
    help: '将在官网会议列表中置顶展示',
  },
  {
    component: 'RichTextarea',
    componentProps: {
      width: '100%',
      options: { min_height: 400, max_height: 700 },
    },
    fieldName: 'introduction',
    label: '会议介绍',
    formItemClass: 'col-span-2',
    // help: () => {
    //   return (
    //     <div class="flex flex-col items-center">
    //       <img
    //         alt=""
    //         class="mb-[10px] w-[120px]"
    //         src="https://resource.iteschina.com/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%A0%81/ITES%E5%B7%A5%E4%B8%9A%E5%B1%95/richtext-example.png"
    //       />
    //       <p>扫码可查看示例效果展示</p>
    //     </div>
    //   );
    // },
  },
  // {
  //   component: 'SourceSelect',
  //   fieldName: 'sourceId',
  //   label: '关联来源',
  //   rules: 'selectRequired',
  // },
  // {
  //   component: 'RadioGroup',
  //   componentProps: {
  //     buttonStyle: 'solid',
  //     options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
  //     optionType: 'button',
  //   },
  //   defaultValue: '0',
  //   fieldName: 'status',
  //   label: '状态',
  //   rules: 'selectRequired',
  // },
  // {
  //   component: 'Textarea',
  //   fieldName: 'remark',
  //   label: '备注',
  // },
  {
    component: 'Divider',
    componentProps: {
      id: 'enrollSetting',
      orientation: 'center',
    },
    fieldName: 'enrollSetting',
    formItemClass: 'col-span-2',
    hideLabel: true,
    renderComponentContent: () => ({
      default: () => '报名配置',
    }),
  },
  {
    component: 'InputNumber',
    fieldName: 'freeAmount',
    label: '免门票金额',
    componentProps: {
      min: 0,
    },
    help: '官网会议报名按钮上展示的免门票划线金额，不填默认为50元',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 0,
    fieldName: 'isRealName',
    label: '实名填写',
    help: '开启后，官网报名登记时需要填写证件号码',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 1,
    fieldName: 'hasEntryCode',
    label: '显示入场码',
    help: '开启后，报名成功后将展示入场二维码',
  },
  {
    component: 'Textarea',
    fieldName: 'entryDesc',
    formItemClass: 'col-span-2',
    label: '无码提示文案',
    componentProps: {
      autoSize: { minRows: 4 },
      placeholder: '请输入参会人报名后无入场码的情况下显示的提示文案',
    },
    help: '关闭显示入场码时，需填写此内容',
    rules: 'required',
    dependencies: {
      if: (values) => values.hasEntryCode === 0,
      triggerFields: ['hasEntryCode'],
    },
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 0,
    fieldName: 'isAudit',
    label: '需要审核',
    help: '开启后，通过会议邀请函报名后将进入审核流程',
  },
  {
    component: 'Textarea',
    fieldName: 'enrollSuccessDesc',
    formItemClass: 'col-span-2',
    label: '审核成功提示',
    componentProps: {
      autoSize: { minRows: 4 },
      placeholder: '请输入参会人员报名并审核通过后，显示的提示文案',
    },
    help: '开启需要审核开关后，参会认报名后将进入审核流程，审核通过后将展示此提示内容',
    dependencies: {
      if: (values) => values.isAudit === 1,
      triggerFields: ['isAudit'],
    },
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.MEETING_CHARGE_TYPE, true),
      optionType: 'button',
    },
    defaultValue: 0,
    formItemClass: 'col-span-2',
    fieldName: 'chargeType',
    label: '收费类型',
    help: '配置会议报名收费模式',
  },
  {
    component: 'RichTextarea',
    componentProps: {
      width: '100%',
      options: { min_height: 400, max_height: 600 },
    },
    fieldName: 'enrollProcessDesc',
    label: '线下报名流程',
    help: '会议详情页面将展示该流程内容',
    formItemClass: 'col-span-2',
    dependencies: {
      if: (values) => values.chargeType === 1,
      triggerFields: ['chargeType'],
    },
  },
  {
    component: markRaw(MeetingChargeMode),
    defaultValue: [],
    disabledOnChangeListener: false,
    fieldName: 'chargeModes',
    formItemClass: 'col-span-2',
    label: '收费模式',
    dependencies: {
      if: (values) => values.chargeType === 2,
      triggerFields: ['chargeType'],
    },
    rules: z
      .array(
        z.object({
          name: z.string().min(1, '收费选项名称不能为空'),
          amount: z.preprocess(
            (val) => {
              if (typeof val === 'string' && val.trim() !== '') {
                const num = Number(val);
                return Number.isNaN(num) ? val : num;
              }
              return val;
            },
            z
              .number({
                required_error: '金额不能为空',
                invalid_type_error: '请输入有效的数字',
              })
              .positive('金额必须大于 0'),
          ),
        }),
      )
      .nonempty('至少需要一个收费选项'),
  },
  {
    component: 'Textarea',
    fieldName: 'smsContent',
    formItemClass: 'col-span-2',
    label: '报名成功短信',
    componentProps: {
      autoSize: { minRows: 4 },
      placeholder:
        '如需增加姓名标识，可插入{姓名}符号，如"尊敬的{姓名}，您好！"',
    },
    help: '报名成功后参会人员收到的短信通知内容',
  },
  {
    component: 'Divider',
    componentProps: {
      id: 'visibleSetting',
      orientation: 'center',
    },
    fieldName: 'visibleSetting',
    formItemClass: 'col-span-2',
    hideLabel: true,
    renderComponentContent: () => ({
      default: () => '上线配置',
    }),
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 1,
    fieldName: 'isWebSiteDisplay',
    label: '官网',
    help: '是否在官网会议中心板块中展示',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 1,
    fieldName: 'isMiniProgramDisplay',
    label: '小程序',
    help: '是否在易会通小程序中展示',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 0,
    fieldName: 'isRegisterPageDisplay',
    label: '登记页',
    help: '是否在官网预登记流程中的推荐会议环节展示',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 0,
    fieldName: 'isDirect',
    label: '定向',
    // help: '',
  },
  {
    component: 'Divider',
    componentProps: {
      id: 'contactSetting',
      orientation: 'center',
    },
    fieldName: 'contactSetting',
    formItemClass: 'col-span-2',
    hideLabel: true,
    renderComponentContent: () => ({
      default: () => '会议咨询',
    }),
  },
  {
    component: 'Textarea',
    fieldName: 'contactWay',
    label: '联系方式',
    componentProps: {
      autoSize: { minRows: 4 },
    },
    help: '将在官网会议详情页右侧的会议合作板块显示会务联系方式',
  },
  {
    component: 'Divider',
    componentProps: {
      id: 'reviewSetting',
      orientation: 'center',
    },
    fieldName: 'reviewSetting',
    formItemClass: 'col-span-2',
    hideLabel: true,
    renderComponentContent: () => ({
      default: () => '会议回顾',
    }),
  },
  {
    component: 'RichTextarea',
    componentProps: {
      width: '100%',
      options: { min_height: 400, max_height: 700 },
    },
    fieldName: 'contentReview',
    label: '会议回顾',
    help: '会议结束后，会议详情页面将会展示此回顾内容',
    description: '注：会议结束后才展示此内容',
    wrapperClass: 'flex-col items-start',
    formItemClass: 'col-span-2',
  },
];

export const detailsSchema: DetailsModalSchemaGetter = () => [
  {
    label: '会议名称',
    fieldName: 'name',
    copy: true,
  },
  {
    label: '会议类型',
    fieldName: 'type',
    dictEnum: DictEnum.MEETING_TYPE,
  },
  {
    label: '会议系列',
    fieldName: 'seriesName',
    copy: true,
  },
  {
    label: '会议主题',
    fieldName: 'theme',
    copy: true,
  },
  {
    label: '主办方',
    fieldName: 'sponsor',
  },
  {
    label: '会议地点',
    fieldName: 'address',
    copy: true,
  },
  {
    label: '会议时间',
    fieldName: 'stratTime',
    copy: (info: any) => {
      return `${info.startTime} ~ ${info.endTime}`;
    },
    slots: {
      default: (info) => {
        return (
          <span>
            {info.startTime} ~ {info.endTime}
          </span>
        );
      },
    },
  },
  {
    label: '会议标签',
    fieldName: 'labels',
    custom: true,
  },
  {
    label: '直播地址',
    fieldName: 'liveStreamUrl',
  },
  {
    label: '缩略图',
    fieldName: 'thumbnailUrl',
    slots: {
      default: (info) => {
        return (
          <Image
            key={info.thumbnailUrl}
            src={info.thumbnailUrl}
            width="200px"
          />
        );
      },
    },
  },
  {
    label: '是否置顶',
    fieldName: 'isTop',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '会议介绍',
    fieldName: 'introduction',
    slots: {
      default: (info) => {
        return <div innerHTML={info.introduction}></div>;
      },
    },
  },
  {
    label: '免门票金额',
    fieldName: 'freeAmount',
  },
  {
    label: '实名填写',
    fieldName: 'isRealName',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '显示入场码',
    fieldName: 'hasEntryCode',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '无码提示文案',
    fieldName: 'entryDesc',
    dependencies: {
      if: (values) => values.hasEntryCode === 0,
      triggerFields: ['hasEntryCode'],
    },
    textWrap: true,
  },
  {
    label: '需要审核',
    fieldName: 'isAudit',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '审核成功提示',
    fieldName: 'enrollSuccessDesc',
    dependencies: {
      if: (values) => values.isAudit === 1,
      triggerFields: ['isAudit'],
    },
    textWrap: true,
  },
  {
    label: '收费类型',
    fieldName: 'chargeType',
    dictEnum: DictEnum.MEETING_CHARGE_TYPE,
  },
  {
    label: '线下报名流程',
    fieldName: 'enrollProcessDesc',
    slots: {
      default: (info) => {
        return <div innerHTML={info.enrollProcessDesc}></div>;
      },
    },
    dependencies: {
      if: (values) => values.chargeType === 1,
      triggerFields: ['chargeType'],
    },
  },
  {
    label: '收费模式',
    fieldName: 'chargeModes',
    slots: {
      default: (info) => {
        if (info.chargeModes?.length === 0) return '';

        return (
          <div>
            {info.chargeModes.map((item: any) => (
              <div key={item.id}>
                <span>{item.name}</span> / <span>¥{item.amount}</span>
              </div>
            ))}
          </div>
        );
      },
    },
    dependencies: {
      if: (values) => values.chargeType === 2,
      triggerFields: ['chargeType'],
    },
  },
  {
    label: '报名成功短信',
    fieldName: 'smsContent',
    textWrap: true,
  },
  {
    label: '官网展示',
    fieldName: 'isWebSiteDisplay',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '小程序展示',
    fieldName: 'isMiniProgramDisplay',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '登记页推荐',
    fieldName: 'isRegisterPageDisplay',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '定向展示',
    fieldName: 'isDirect',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '联系方式',
    fieldName: 'contactWay',
    textWrap: true,
  },
  {
    label: '会议回顾',
    fieldName: 'contentReview',
    slots: {
      default: (info) => {
        return <div innerHTML={info.contentReview}></div>;
      },
    },
  },
  // {
  //   label: '备注',
  //   fieldName: 'remark',
  // },
];
